﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Transactions;
using AB.ServiceDirectory.Entities;
using NUnit.Framework;
using AB.ServiceDirectory.BO;
namespace AB.ServiceDirectory.TestScripts
{
    [TestFixture]
    class ServiceTab23ContractTesting
    {
        private int _serviceId;
        [SetUp]
        public void SetUp()
        {
            _serviceId = 1;
        }
        [Test]
        public void TestAddService2_SingleCheck_ReturnTrue()
        {
            using (var trans = new TransactionScope())
            {
                var service = new Service();
                var serviceReference = new ServiceReference();
                var checkboxBenefit = new string[] { "1" };

                service.ServiceName = "ABC";
                service.ShortDescription = "ABC";
                service.DeptCode = "123";
                service.ServiceType = "1";
                service.ContactId = 1;
                service.IsActive = true;
                service.SubType = "1";
                foreach (var benefit in checkboxBenefit)
                {
                    serviceReference.BenefitsCriterion = string.Join("-", benefit);
                }

                service.ServiceReference = serviceReference;
                Assert.IsTrue(ServiceDetail2BO.AddService2(service));
            }
        }
        [Test]
        public void TestAddService2_MultipleCheck_ReturnTrue()
        {
            using (var trans = new TransactionScope())
            {
                var service = new Service();
                var serviceReference = new ServiceReference();
                var checkboxBenefit = new string[] { "1", "2" };
                
                service.ServiceName = "ABC";
                service.ShortDescription = "ABC";
                service.DeptCode = "123";
                service.ServiceType = "1";
                service.ContactId = 1;
                service.IsActive = true;
                service.SubType = "1";
                foreach (var benefit in checkboxBenefit)
                {
                    serviceReference.BenefitsCriterion = string.Join("-", benefit);
                }

                service.ServiceReference = serviceReference;
                Assert.IsTrue(ServiceDetail2BO.AddService2(service));
            }
        }
        [Test]
        public void TestEditService2_SingleCheck_ReturnTrue()
        {
            using (var trans = new TransactionScope())
            {
                var service = new Service();
                var serviceContract = new ServiceContract();
                var serviceReference = new ServiceReference();
                var checkboxContractOutcome = new string[]{ "1" };
                var checkboxReference = new string[] { "1" };
                foreach (var contractOutcome in checkboxContractOutcome)
                {
                    serviceContract.ContractOutcome = string.Join("-", contractOutcome);
                }
                foreach (var reference in checkboxReference)
                {
                    serviceReference.DisabilityCriterion = string.Join("-", reference);
                }

                service.ServiceId = _serviceId;
                service.ServiceContract = serviceContract;
                service.ServiceReference = serviceReference;
                Assert.IsTrue(ServiceDetail2BO.EditService2(service));
            }
        }
        [Test]
        public void TestEditService2_MultipleCheck_ReturnTrue()
        {
            _serviceId++;
            using (var trans = new TransactionScope())
            {
                var service = new Service();
                var serviceContract = new ServiceContract();
                var serviceReference = new ServiceReference();
                var checkboxContractOutcome = new string[] { "1", "2" };
                var checkboxReference = new string[] { "1", "2" };
                foreach (var contractOutcome in checkboxContractOutcome)
                {
                    serviceContract.ContractOutcome = string.Join("-", contractOutcome);
                }
                foreach (var reference in checkboxReference)
                {
                    serviceReference.DisabilityCriterion = string.Join("-", reference);
                }

                service.ServiceId = 2;
                service.ServiceContract = serviceContract;
                service.ServiceReference = serviceReference;
                Assert.IsTrue(ServiceDetail2BO.EditService2(service));
            }
        }
    }
}
